package com.hyx.api.controller.applet_recover;

import com.hyx.api.config.ApiPrefixRestController;
import com.hyx.api.domain.bo.*;
import com.hyx.api.domain.vo.RecoverInquiryOrderListVo;
import com.hyx.api.service.IAppCommonService;
import com.hyx.api.service.IAppRecoverService;
import com.hyx.api.service.IAppShopService;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@ApiPrefixRestController
@RequestMapping("/appRecoverApi/order")
public class RecoverOrderController extends BaseController {

    @Autowired
    private IAppRecoverService recoverService;

    @Autowired
    private IAppShopService appShopService;
    @Autowired
    private IAppCommonService appCommonService;

    /**
     * 根据报价状态获取订单列表
     * 0：未报价
     * 1：报价中
     * 3：待支付
     */
    @GetMapping("/inquiryOrder/list")
    public TableDataInfo queryInquiryOrderList(@RequestParam("offerStatus") Integer offerStatus) {
        startPage();
        List<RecoverInquiryOrderListVo> list = recoverService.queryInquiryOrderList(offerStatus);
        return getDataTable(list);
    }

    /**
     * 查询询价订单是否可以报价   --- 未使用
     */
    @GetMapping("/queryIsAllowOffer")
    public AjaxResult queryIsAllowOffer(@RequestParam("inquiryOrderId") Integer inquiryOrderId) {
        return recoverService.queryIsAllowOffer(inquiryOrderId);
    }

    /**
     * 获取关于询价订单的报价信息
     */
    @GetMapping("/queryOfferOrderByInquiryId")
    public AjaxResult queryOfferOrderByInquiryId(@RequestParam("inquiryOrderId") Integer inquiryOrderId) {
        return recoverService.queryOfferOrderByInquiryId(inquiryOrderId);
    }

    /**
     * 创建报价订单   --- 对接
     */
    @PostMapping("/addOfferOrder")
    @RepeatSubmit
    public AjaxResult addOfferOrder(@RequestBody OfferOrderBo bo) {
        return recoverService.addOfferOrder(bo);
    }

    /**
     * 更新报价订单 --- 对接
     */
    @PostMapping("/updateOfferOrder")
    public AjaxResult updateOfferOrder(@RequestBody OfferOrderBo bo) {
        return recoverService.updateOfferOrder(bo);
    }

    /**
     * 回收订单确认收货 --- 对接
     */
    @PostMapping("/recycleOrderConfirmReceiving")
    public AjaxResult recycleOrderConfirmReceiving(@RequestBody RecOrderStaUpdateBo bo) {
        return recoverService.recycleOrderConfirmReceiving(bo);
    }

    /**
     * 创建退货订单 --- 对接
     */
    @GetMapping("/refundOrderCreate")
    public AjaxResult refundOrderCreate(Long recycleOrderId) {
        return recoverService.refundOrderCreate(recycleOrderId);
    }

    /**
     * 生成追差订单  --- 对接
     *
     * @param bo
     * @return
     */
    @PostMapping("/addSpreadOrder")
    public AjaxResult addSpreadOrder(@RequestBody SpreadOrderBo bo) {
        return recoverService.addSpreadOrder(bo);
    }

    /**
     * 修改追差订单 --- 对接
     *
     * @param bo
     * @return
     */
    @PostMapping("/updateSpreadOrder")
    public AjaxResult updateSpreadOrder(@RequestBody SpreadOrderBo bo) {
        return recoverService.updateSpreadOrder(bo);
    }

    /**
     * 审核加价审批订单
     *
     * @param req
     * @return
     */
    @PostMapping("/auditSpreadOrder")
    public AjaxResult auditSpreadOrder(@RequestBody SpreadOrderBo req) {
        return appShopService.auditSpreadOrder(req);
    }

    /**
     * 获取订单详情-通过询价订单关联 ---- 使用
     *
     * @param inquiryOrderId
     * @return
     */
    @GetMapping("/queryInquiryOrderDetail")
    public AjaxResult queryInquiryOrderDetail(@RequestParam Long inquiryOrderId) {
        return recoverService.queryInquiryOrderDetail(inquiryOrderId);
    }

    /**
     * 获取报价师工作台数量                      --- 对接
     * queTime 格式为：yyyy-MM-dd,不传则默认当天
     *
     * @return
     */
    @GetMapping("/queryRecoverWorkCount")
    public AjaxResult queryRecoverWorkCount(Map<String, String> map) {
        String queTime = map.get("queTime");
        return recoverService.queryRecoverWorkCount(queTime);
    }

    /**
     * 获取回收商统计信息-根据当前用户
     *
     * @param bo
     * @return
     */
    @PostMapping("/queryRecycleStaticsInfo")
    public AjaxResult queryRecycleStaticsInfo(@RequestBody RecycleStaticsQueBo bo) {
        return recoverService.queryRecycleStaticsInfo(bo);
    }

    /**
     * 获取报价订单的消息
     *
     * @param offerOrderId
     * @return
     */
    @GetMapping("/queryMsgDialogueList")
    public AjaxResult queryMsgDialogueList(@RequestParam Long offerOrderId) {
        return recoverService.queryMsgDialogueList(offerOrderId);
    }

    /**
     * 获取回收商回收订单列表 --- 对接
     *
     * @param req
     * @return
     */
    @PostMapping("/queryRecycleOrderList")
    public TableDataInfo queryRecycleOrderList(@RequestBody ShopRecOrderQueBo req) {
        startPage();
        return getDataTable(appCommonService.queryRecycleOrderList(req));
    }

    /**
     * 获取回收商工作台统计信息-只能总账户使用  --- 对接
     *
     * @return
     */
    @GetMapping("/queryRecycleStatistic")
    public AjaxResult queryRecycleStatistic() {
        return recoverService.queryRecycleStatistic();
    }

    /**
     * 获取订单列表-回收商相关 --- 对接
     *
     * @param status
     * @return
     */
    @GetMapping("/queryOrderListByRecycle")
    public TableDataInfo queryOrderListByRecycle(@RequestParam("status") Integer status) {
        startPage();
        return getDataTable(recoverService.queryOrderListByRecycle(status, null));
    }

}
